import { GameError } from './GameError';

/**
 * 任务相关错误类
 */

/**
 * 任务不存在错误
 */
export class TaskNotFoundError extends GameError {
    readonly code = 'TASK_NOT_FOUND';
    readonly statusCode = 404;

    constructor(taskId: string) {
        super(`任务不存在：${taskId}`, { taskId });
    }
}

/**
 * 任务已完成错误
 */
export class TaskAlreadyCompletedError extends GameError {
    readonly code = 'TASK_ALREADY_COMPLETED';
    readonly statusCode = 409;

    constructor(taskId: string) {
        super(`任务已完成：${taskId}`, { taskId });
    }
}

/**
 * 任务条件不满足错误
 */
export class TaskConditionNotMetError extends GameError {
    readonly code = 'TASK_CONDITION_NOT_MET';
    readonly statusCode = 403;

    constructor(taskId: string, condition: string) {
        super(`任务 ${taskId} 条件不满足：${condition}`, {
            taskId,
            condition
        });
    }
}

/**
 * 任务进度无效错误
 */
export class InvalidTaskProgressError extends GameError {
    readonly code = 'INVALID_TASK_PROGRESS';
    readonly statusCode = 400;

    constructor(taskId: string, progress: number, maxProgress: number) {
        super(`任务 ${taskId} 进度无效：${progress}/${maxProgress}`, {
            taskId,
            progress,
            maxProgress
        });
    }
}

/**
 * 任务奖励领取错误
 */
export class TaskRewardClaimError extends GameError {
    readonly code = 'TASK_REWARD_CLAIM_ERROR';
    readonly statusCode = 400;

    constructor(taskId: string, reason: string) {
        super(`任务 ${taskId} 奖励领取失败：${reason}`, {
            taskId,
            reason
        });
    }
}

/**
 * 世界任务错误
 */
export class WorldTaskError extends GameError {
    readonly code = 'WORLD_TASK_ERROR';
    readonly statusCode = 500;

    constructor(taskType: string, reason: string) {
        super(`世界任务 ${taskType} 错误：${reason}`, {
            taskType,
            reason
        });
    }
}

/**
 * 任务配置错误
 */
export class TaskConfigError extends GameError {
    readonly code = 'TASK_CONFIG_ERROR';
    readonly statusCode = 500;

    constructor(configKey: string, reason: string) {
        super(`任务配置错误：${configKey}，原因：${reason}`, {
            configKey,
            reason
        });
    }
}

/**
 * 通用任务错误
 */
export class TaskError extends GameError {
    readonly code = 'TASK_ERROR';
    readonly statusCode = 500;

    constructor(message: string, data?: any) {
        super(message, data);
    }
}